'''
Descripttion: 自编码器 两个网络 一个复杂一个简单
Author: Haixu He
Date: 2021-12-20 14:51:18
'''
import numpy as np
import matplotlib.pyplot as plt
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
from torch.utils.data import DataLoader, dataloader
import pandas as pd

# 定义网络
class autoencoder(nn.Module): 
    def __init__(self, in_dim,out_dim):
        super(autoencoder, self).__init__()
        #编码器
        self.encoder = nn.Sequential(
            nn.Linear(in_dim, 8),
            nn.ReLU(True),
            nn.Linear(8, 3)  # 输出的 code 是 3 维，便于可视化
        )
        #解码器
        self.decoder = nn.Sequential(
            nn.Linear(3, 8),
            nn.ReLU(True),
            nn.Linear(8, out_dim),
            nn.Tanh()  #使输出范围在-1~1
        )

    def forward(self, x):
        encode = self.encoder(x)
        decode = self.decoder(encode)
        return encode, decode

# # 定义网络
# class autoencoder(nn.Module):
#     def __init__(self, in_dim,out_dim):
#         super(autoencoder, self).__init__()
#         #编码器
#         self.encoder = nn.Sequential(
#             nn.Linear(in_dim, 128),
#             nn.ReLU(True),
#             nn.Linear(128, 64),
#             nn.ReLU(True),
#             nn.Linear(64, 12),
#             nn.ReLU(True),
#             nn.Linear(12, 3)  # 输出的 code 是 3 维，便于可视化
#         )
#         #解码器
#         self.decoder = nn.Sequential(
#             nn.Linear(3, 12),
#             nn.ReLU(True),
#             nn.Linear(12, 64),
#             nn.ReLU(True),
#             nn.Linear(64, 128),
#             nn.ReLU(True),
#             nn.Linear(128, out_dim),
#             nn.Tanh()  #使输出范围在-1~1
#         )

#     def forward(self, x):
#         encode = self.encoder(x)
#         decode = self.decoder(encode)
#         return encode, decode